package org.example.cprobes;

import java.util.Random;

//import autonomic.manager.context.manager.Context_Manager_Interface;
//import autonomic.manager.context.manager.impl.Context_Manager;

import fr.imag.adele.cprobes.abstracts.AbstractProbe;
import fr.imag.adele.cprobes.services.DataCollector;
import fr.imag.adele.cprobes.services.DataSender;
import fr.imag.adele.cprobes.services.Scheduler;
import fr.imag.adele.cprobes.util.DataEvent;
import fr.imag.adele.cprobes.util.DataSet;


public class CpuProbe extends AbstractProbe {
	 //private Context_Manager_Interface m_cm;
	/**
	 * Process the collected data.
	 * This class implementation of the Probe Service, collect CPU informations and send them
	 * to interested targets.
	 * The provided topics are :
	 * - cpu
	 * - cpu_user
	 * - cpu_kernel
	 * 
	 */	
	public void process() {								
		Random rn = new Random();
		long cpu = rn.nextInt() % 100;
		long cpu_kernel = rn.nextLong() % 100;
		long cpu_user = rn.nextLong() % 100;
		/*	
		long cpu = (long)m_cm.getCpuUsage(0) ;
		long cpu_kernel = (long)m_cm.getCpuUsageKernel(0);
		long cpu_user = (long)m_cm.getCpuUsageUser(0);
		*/		
		DataSet dataSet = new DataSet();
		DataEvent dataEvent1 = new DataEvent("cpu","","",String.valueOf(Math.abs(cpu)), "%", null);
		dataSet.add(dataEvent1);
		DataEvent dataEvent2 = new DataEvent("cpu_user","","",String.valueOf(Math.abs(cpu_kernel)), "%", null);
		dataSet.add(dataEvent2);
		DataEvent dataEvent3 = new DataEvent("cpu_kernel","","",String.valueOf(Math.abs(cpu_user)), "%", null);
		dataSet.add(dataEvent3);
		sendProcessedData(dataSet);
	}
		
	////Binding methods
	// TODO if we can bind directly with methods from the parent class
	// then we have to move these methods to the parent class.
	
	public void bindScheduler(Scheduler scheduler) {			
		setScheduler(scheduler);
	}
	public void unbindScheduler() {
		setScheduler(null);
	}
	public void bindDataCollector(DataCollector dataCollector) {
		setDataCollector(dataCollector);
	}
	public void unbindDataCollector() {
		setDataCollector(null);
	}
	public void bindDataSender(DataSender dataSender) {
		setDataSender(dataSender);
	}
	public void unbindDataSender() {
		setDataSender(null);
	}
	
	////
}
